package com.loveprogrammer.eternity.skill.support.states;

import com.loveprogrammer.eternity.enums.AttackTypeEnum;
import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.model.attack.AttackEntity;
import com.loveprogrammer.eternity.model.attack.AttackResult;
import com.loveprogrammer.eternity.model.console.ConsolePrint;

import java.util.List;

/**
 * @version 1.0.0
 * @description: 中毒
 * @author: eric
 * @date: 2022-08-16 16:45
 **/
public class PoisoningState extends AbstractNegativeState{

    private int reduceHp;

    public PoisoningState(Character character, List<? extends Character> camp, int reduceHp) {
        super(character,camp);
        this.reduceHp = reduceHp;
    }

    @Override
    public int id() {
        return 1;
    }

    @Override
    public String name() {
        return "中毒";
    }

    @Override
    public String desc() {
        return "中毒，每秒钟减血";
    }

    @Override
    public void doReset() {
        getCharacter().removeState(this);
        ConsolePrint.publishMessage(string + getCharacter().getName() + "(" + getCharacter().getCurrentHp() + "/" +
                getCharacter().getHpMax() + ")" + "从中毒状态恢复");
    }

    @Override
    public int counterId() {
        return 99;
    }

    @Override
    public void run() {
        // 如果已经死了就算了
        if(this.getCharacter().checkDead()){
            return;
        }
        // 否则 查看对方的毒抗
        AttackEntity entity = new AttackEntity(reduceHp, AttackTypeEnum.POISON);
        AttackResult defence = getCharacter().defence(entity);
        final int power = defence.getHarm();
        if(power < 0){
            return;
        }
        getCharacter().hp().addAndGet(-power);
        ConsolePrint.publishMessage(string + getCharacter().getName() + "(" + getCharacter().getCurrentHp() + "/" +
                getCharacter().getHpMax() + ")" + "中毒失去生命值" + power);

        if (getCharacter().checkDead()) {
            if(getNotify() == null){
                return;
            }
            getNotify().publishDeadEvent(getCharacter(),getCamp());
        }
    }
}
